package com.plian.system.service.wf;

import com.plian.Tools.CollectionUtil;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.config.exception.MyRuntimeException;
import com.plian.system.model.ObjResult;
import com.plian.system.service.fr.evaluation.IEvaluationApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.plian.system.constant.sys.FormTypeConstant.FR_EVALUATIONAPPROVAL_FORM;
import static com.plian.system.constant.wf.PrivilegeConstant.MODIFY_CODE;

/**
 * 工作流中对单据的特殊操作
 */
@Service
public class FormPrivilegeService {
    @Autowired
    private IEvaluationApprovalService evaluationApprovalService;

    @Transactional
    public void privilege(int formType, String formId, List<Integer> privilegeCodeList, PageData params) throws Exception {
        //noinspection SwitchStatementWithTooFewBranches
        if (CollectionUtil.isNotEmpty(privilegeCodeList)) {
            for (int privilegeCode : privilegeCodeList) {
                switch (privilegeCode) {
                    case MODIFY_CODE:
                        switch (formType) {
                            case FR_EVALUATIONAPPROVAL_FORM:
                                evaluationApprovalService.privilegeToModifyCode(formId, params);
                                break;
                            default:
                                throw new MyRuntimeException(new ObjResult("未知的单据类型！"));
                        }
                        break;
                    default:
                        throw new MyRuntimeException(new ObjResult("未知的特殊操作！"));
                }
            }
        }
    }
}
